<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id='box'>点击一下更改地址</button>
    <script>
        // 获取地址
        console.log(window.location.href);
        var btn = document.getElementById('box');
        btn.onclick = function() {
            window.location.href = 'http://www.baidu.com'
        }


        // 获取地址
        console.log(window.location.href);
        //获取协议
        console.log(window.location.protocol);
        //获取主机名和端口号(如果有)
        console.log(window.location.host)
            //获取主机名
        console.log(window.location.hostname)

        //获取端口号
        console.log(window.location.port)
            //获取当前文件在服务器中的路径或者文件夹
        console.log(window.location.pathname);
        //获取url地址后面?以及它后面的参数
        console.log(window.location.search);
    </script>
</body>

</html>